//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CColorBitmap.h>
///	@path	~/src/gui/image/
///	@date	2008/06/25
///	@desc	.

#pragma once

#include "xeres.h"

#include "gui/image/IBitmap.h"
#include "gui/composite/layer.h"

namespace xeres {

	/*! 
		\class	CColorBitmap
		\brief
	*/
	class CColorBitmap : public IBitmap
	{
	public:

		/// \ctor
		CColorBitmap( size_t width , size_t height , ColorType type , const byte * src );

		/// \ctor
		CColorBitmap( Gdiplus::Bitmap * bitmap );

		/// \dtor
		virtual ~CColorBitmap( void );

		DECL_IOBJECT_CLASS( CColorBitmap , IBitmap );

	public:

		/// \name	Bitmap Interface
		//@{

		/// \brief	Get width of bitmap.
		virtual size_t GetWidth( void );

		/// \brief	Get height of bitmap.
		virtual size_t GetHeight( void );

		/// \brief	Get size of bitmap.
		virtual Pair<int> GetSize( void );

		/// \brief	Get frame count.
		virtual int GetFrame( void );

		/// \brief	Get frame delay.
		virtual float GetDelay( int frame );

		/// \brief	Get storage size.
		virtual size_t GetStorageSize( void );

		/// \brief	Get color type of bitmap (only COLOR_MONO , COLOR_RGB , COLOR_RGBA & COLOR_ARGB is valid ).
		virtual ColorType GetColorType( void );

		/// \brief	Get pixel of bitmap.
		virtual RGBA GetPixel( const Pair<int>& point , int frame );

		/// \brief	Get sampler.
		virtual void GetSampler( const Pair<int>& point , Sampler& sampler , int frame = 0 );

		//@}

	protected:

		// This constructors will leave m_bits as NULL for multi-frame support.

		/// \ctor
		CColorBitmap( size_t width , size_t height , ColorType type );

		/// \ctor
		CColorBitmap( Gdiplus::Bitmap& bitmap );

		/// \brief	Get proper pixel format type.
		static ColorType GetPixelFormatType( Gdiplus::Bitmap * bitmap );

		/// \brief	Allocate space for image.
		static byte * AllocateImage( size_t image_size );

		/// \brief	Deallocate space of image.
		static void Deallocate( byte * image );

		/// \brief	General get pixel function.
		RGBA GetPixelBase( const Pair<int>& point , byte * base );

		/// \brief	Get pixel base offset.
		byte * GetPixelOffset( const Pair<int>& point , byte * offset );

		/// \brief	Make bitmap from source.
		void MakeBitmap( Gdiplus::Bitmap * bitmap , byte * dst );

		//@ data
		size_t			m_width , m_height;
		size_t			m_imageSize;
		size_t			m_pitch;
		ColorType		m_type;
		byte *			m_bits;
	};

} // namespace xeres
